let base = [

  {
    meta: { title: '登录页面', },
    path: '/login',
    name: 'login',
    component: () => import('@/adminCore/views/login'),
  },
  {
    meta: { title: '页面不存在', },
    path: '/404',
    name: '404',
    component: () => import('@adminCore/views/404'),
  },
  {
    meta: { title: '重定向', },
    path: '/:catchAll(.*)', redirect: '/404',
  }
]


function NewRouter() {
  let router = JSON.parse(JSON.stringify(data))
  // router.splice(1, 1)
  // console.log("删除后的路由", router)
  return router
}
//导航
function NewNav() {
  let router = NewRouter()

  //提取路径 
  // structure
  const onlyNum = 1 //唯一数据的时候 导航不需要嵌套
  structure.forEach((item, i, v) => {
    v[i].children = router.flatMap(dataItem => dataItem.path.split("/").shift() == item.p ? dataItem : null).filter(noEmpty => noEmpty)
    if (item.children.length == onlyNum) {
      v[i] = item.children
    }
  })
  let res = structure.flat(Infinity)

  return res
}

let structure = [
  {
    mate: "数据监视",
    type: "pie-chart",
    p: 'watch',
    children: []
  },
  {
    mate: "文章管理",
    type: "pie-chart",
    p: 'article',
    children: []
  },
  {
    meta: "友链",
    type: "pie-chart",
    p: "friends",
    children: [],
  },
  {
    meta: "图片",
    p: "picture",
    children: [],
  },
]

let data = [

  {
    meta: { title: '监视数据' },
    path: 'watch/index',
    name: 'watch-index',
    type: "pie-chart",
  },
  {
    meta: { title: '博客日志' },
    path: 'watch/log',
    name: 'watch-log',
    type: "pie-chart",
  },
  {
    meta: { title: '编辑文章' },
    path: 'article/editor',
    name: 'article-editor',
    // type: "pie-chart"
  },
  {
    meta: { title: '浏览文章' },
    path: 'article/see',
    name: 'article-see',
  },
  {
    meta: { title: '编辑历史' },
    path: 'article/edithistory',
    name: 'article-edithistory',
  },
  {
    meta: { title: '编辑文章二' },
    path: 'article/two',
    name: 'article-two',
  },
  {
    meta: { title: '图床' },
    path: 'picture/handle',
    name: 'picture-handle',
    //  导航参数
    type: "pie-chart"
  },
  {
    meta: { title: '友链编辑' },
    path: 'friends/index',
    name: 'friends',
    //  导航参数
    type: "pie-chart"
  },

]
export default {
  NewRouter, base, NewNav
}